//
//  FetchImage.swift
//  SwiftUILean
//
//  Created by wyknmjj on 2024/5/14.
//

import SwiftUI


func fetchImage(_ url:String)async throws -> UIImage{
    guard let u=URL(string: url) else{
        throw NSError(domain:"parse url fail with \(url)",code: 0)
    }
    let (data, _) = try await URLSession.shared.data(from: u)
    guard let image = UIImage(data: data) else {
        throw NSError(domain: "InvalidImageData", code: 0, userInfo: nil)
    }
    return image
}
